﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.CommonFilter;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;

namespace WSDZ.KM.ZH.MatListCostSearchChangeColor
{
    [Description("物料清单成本查询修改颜色"), HotUpdate]
    public class ChangeColor : AbstractDynamicFormPlugIn
    {
        public string btype = "物料清单成本查询修改颜色";
        public string entyKey = "FBottomEntity";
        public override void OnEntrySum(EntrySumEventArgs e)
        {
            base.OnEntrySum(e);
            try
            {
                EntryEntity entryEntity = this.View.BillBusinessInfo.GetEntryEntity(entyKey);
                DynamicObjectCollection datas = this.Model.GetEntityDataObject(entryEntity);
                if (datas == null || datas.Count < 1)
                    return;
                List<int> serList = datas.Where(x => x["Price"].ToStringV1().ToDecimalV1() == 0 ).Select(x => x["Seq"].ToStringV1().ToInt32V1()).ToList();
                if (serList != null && serList.Count > 0)
                {
                    List<KeyValuePair<int, string>> colors = new List<KeyValuePair<int, string>>();
                    serList.ForEach(x =>
                    {
                        colors.Add(new KeyValuePair<int, string>(x - 1, "#ff0015"));
                    });
                    var grid = this.View.GetControl<EntryGrid>(entyKey);
                    grid.SetRowBackcolor(colors);
                }
            }
            catch (Exception ex)
            {
                View.ShowErrMessage(ex.Message);
            }
        }
    }

}
